package com.jf3q.common.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jf3q.common.domain.EduComment;
import com.jf3q.common.domain.EduCommentReply;
import com.jf3q.common.mapper.EduCommentMapper;
import com.jf3q.common.mapper.EduCommentReplyMapper;
import com.jf3q.common.service.EduCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class EduCommentServiceImpl extends ServiceImpl<EduCommentMapper, EduComment>
    implements EduCommentService {
    @Autowired
    EduCommentReplyMapper commentReplyMapper;
    public Page<EduComment> getPage(Integer pageindex, String rating) {
        LambdaQueryWrapper<EduComment> queryWrapper=new LambdaQueryWrapper<>();
        if (rating.equals("good")){
            queryWrapper.eq(EduComment::getRating,rating);
        }
        if (rating.equals("average")){
            queryWrapper.eq(EduComment::getRating,rating);
        }
        if (rating.equals("bad")){
            queryWrapper.eq(EduComment::getRating,rating);
        }
        queryWrapper.orderByDesc(EduComment::getEduCreate);
        Page<EduComment> page = this.page(new Page<>(pageindex, 3), queryWrapper);
        for (EduComment record : page.getRecords()) {
            LambdaQueryWrapper <EduCommentReply> queryWrappe=new LambdaQueryWrapper<>();
            queryWrappe.eq(EduCommentReply::getCommentId,record.getId());
            List<EduCommentReply> list= commentReplyMapper.selectList(queryWrappe);
             if (list!=null&&list.size()!=0){
                 record.setReplies(list);
             }
        }
        return page;
    }

    public Integer selectRating(String s) {
       return commentReplyMapper.selectRacount(s);
    }
}




